home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tc2cs.arc / PSPADDRS.C < prev    next >
Text File  |  1987-03-13  |  4KB  |  105 lines

  1. /* This program 
  2.     - prints the addresses of all the PSP's currently being used in memory and
  3.         the handles opened in each of those processes.
  4.         Handy if you have a lot of parent and child processes loaded.
  5.     - was compiled using Lattice 3.00h
  6.     - ASSUMES small memory model.  I was too lazy to do a segread() to get the
  7.         ds register.  Instead, I took Lattice's value in _SS since ds == ss.
  8.     - ASSUMES your environment area does not exceed 1000 bytes.  If it does you
  9.         need to change the array, environment, and the value in movedata().
  10.         DOS can have an environment that 32K, though most people don't make it
  11.         that large.
  12.         
  13.   */
  14.  
  15. struct PROG_S_PRE {
  16.  unsigned int interrpt;    /* first two bytes are the instruction int 20h */
  17.                     /* this is a carryover from CP/M when you could */
  18.                     /* jump to the first byte of your program to exit */
  19.  unsigned int machine;    /* Memory size in paragraphs (16-bytes blocks) */
  20.  char dos1;
  21.  char call_dis[5];        /* FAR CALL to MS-DOS function dispatcher */
  22.  unsigned long Int22;    /* previous INT 22h, terminate process address IP,CS */
  23.  unsigned long Int23;    /* previous INT 23h, CNTRL-C exit address IP,CS */
  24.  unsigned long Int24;    /* previous INT 24h, Critical Error address IP,CS */
  25.  unsigned int pre_psp;    /* previous PSP segment */
  26.  unsigned char hndl[20];    /* file handles - FF means the handle not assigned */
  27.  unsigned int environ;    /* segment address of the environment block */
  28.  char dos2[34];
  29.  char dispatch[12];        /* code to call MS-DOS dispatcher INT 21 instructions */
  30.  char fcb1[16];        /* unopened File Control Block #1 */
  31.  char fcb2[16];        /* unopened File Control Block #2 */
  32.  char dos3[4];
  33.  char dta[128];            /* default Disk Transfer Area */
  34.  } ps;
  35.  
  36. extern int _psp;
  37. extern int _env;
  38. extern int _esize;
  39. extern int _ss;
  40. char environment[1000];
  41. char command_com[] = "COMMAND.COM";
  42. char *double_null();
  43.  
  44. void main()
  45. {
  46.  
  47.     unsigned int psp;
  48.     char *p;
  49.     int first_time = 1;
  50.     
  51.     if( *(long *)(_env+_esize-2) != 0x00010000 )
  52.     {
  53.         cprintf("Your operating system does not have the name of your\n");
  54.         cprintf("program at the end of the environment.  You need DOS 3.0 or\n");
  55.         cprintf("above.  Or you are running Novell Advance Netware ver 1.02\n");
  56.         cprintf("which clobbers the name area.\n");
  57.         _exit(1);
  58.     }
  59.  
  60.     psp = *(&_psp+1);        /* get the segment word not the offset word */
  61.     do
  62.     {
  63. /* move chucks of memory into our data segment area so that we can work with it */
  64.         movedata( psp, 0, _ss, &ps, sizeof( struct PROG_S_PRE) );
  65.         movedata( ps.environ, 0, _ss, &environment, 1000 );
  66.  
  67. /* easy way to get progname for current program */
  68.         if( first_time )
  69.         {
  70.             cprintf("I'm %s with machine memory of %dK\n\n",
  71.                 ( _env + _esize +2 ), ps.machine >> 6 );
  72.             first_time = 0;
  73.         }
  74.  
  75.         if( ps.environ )    /* for COMMAND.COM */
  76.         {
  77.  
  78. /* find the name of the program following the environment space, Page 4-3 of
  79.     MS-DOS manual, document # 8411-310-02, part # 036-014-012 */
  80.                 p = environment;
  81.                 while( *double_null( &p ));
  82.             p += 3;
  83.         } else {
  84.             p = command_com;
  85.         }
  86.         cprintf("psp at %dK for %s", psp>>6, p );
  87.  
  88. /* display which handles are active for each program */
  89.         /* the field psp is being used as a work int - not good form but ...*/
  90.         for( psp = 0; psp < 20; psp++)
  91.         {
  92.             if( ps.hndl[psp] != 0xff )
  93.                 cprintf(" %d",psp);
  94.         }
  95.         cprintf("\n");
  96.         psp = ps.pre_psp;
  97.     } while( ps.environ );        /* COMMAND.COM has nulls in this field */
  98. }
  99. char *double_null( p )
  100. char **p;
  101. {
  102.     while( *(*p)++ );
  103.     return( *p );
  104. }
  105.